<template>
  <div class="notchangeinp">
    <div class="top">
      <div class="nav-title">推荐搜索</div>
      <div class="nav-item-box">
        <div class="nav-item" v-for="(value,j) in hotWord" :key="j">{{value}}</div>
      </div>

      <div class="content-item-box">
        <van-tabs animated @click="getId(active)" v-model="active">
          <van-tab
            v-for="(item, index) in contentTitleData"
            :title="item.categoryName"
            :key="index"
          >
            <div class="content-item">
              <p class="content-item-title">
                {{ item.categoryName
                }}<van-icon name="fire-o" color="#ee0a24" />
              </p>

              <div
                class="content"
                v-for="(val, i) in contentListeData"
                :key="i"
              >
                <span>{{ i + 1 }}</span>
                {{ val.display_word }}
              </div>
              <span class="most">查看更多<van-icon name="arrow" /></span>
            </div>
          </van-tab>
        </van-tabs>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "notchangeinp",
  data() {
    return {
      contentTitleData: [],
      contentListeData: [],
      active: 0,
      num: -1,
      hotWord:[]
    };
  },
  created() {
    this.getTitleData();
    this.getNameData(this.num);
    this.getHotData()
  },
  methods: {
    getTitleData() {
      this.axios({
        method: "get",
        url: "https://apis.netstart.cn/ximalaya/search/hotWordBillboardCategory",
      })
        .then((value) => {
          // console.log(value);
          this.contentTitleData = value.data.category;
        //   console.log(this.contentTitleData);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getNameData(num) {
      this.axios({
        method: "get",
        url: "https://apis.netstart.cn/ximalaya/search/hotWordBillboardList?size=10",
        params: {
          categoryId: num,
        },
      })
        .then((result) => {
          //   console.log(result);
          this.contentListeData = result.data.hotWordResultList;
        //   console.log(this.contentListeData);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getId(active) {
      // console.log(action);
      let num = this.contentTitleData[active].categoryId;
      // console.log(num);
      this.getNameData(num);
      this.getHotData()
    },
    getHotData() {
      this.axios({
        method: "get",
        url: "https://apis.netstart.cn/ximalaya/search/words",
        
      })
        .then((result) => {
            // console.log(result);
            let arr = result.data.data;
            let num = 11;
            let newArr = [];
            
            // console.log(this.hotWord);
            for (let i = 0; i < num; i++) {
                let ran = Math.floor(Math.random() * arr.length);
                newArr.push(arr.splice(ran,1)[0]) 
            }
            this.hotWord = newArr
          
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.nav-title {
  font-size: 16px;
  padding: 0 10px;
}
.nav-item-box {
  margin-top: 5px;
  padding: 0 20px;
  font-size: 12px;
}
.nav-item {
  background-color: rgb(247, 248, 250);
  display: inline-block;
  padding: 2px 3px;
  border-radius: 10px;
  margin-right: 5px;
  margin-top: 5px;
  color: dimgray;
}
.content-item-box {
  padding: 0 10px;
  margin-top: 30px;
  overflow-y: hidden;
  white-space: nowrap;
  overflow-x: scroll;
  .content-item {
    width: 355px;
    height: 370px;
    box-shadow: -1px -1px 2px 1px #ccc inset;
    display: inline-block;
    border-radius: 10px;
    // margin-left: 10px;

    .content {
      font-size: 14px;
      padding: 5px 15px;
      color: rgb(139, 139, 139);
      
      span {
        margin-right: 10px;
      }
    }

    .most{
          font-size: 14px;
          display: inline-block;
          color: rgb(139, 139, 139);
          text-align: center;
          padding: 0 142px;
          border-top: 1px solid #ccc;
      }
  }
}
</style>